package Tra

import org.apache.spark.sql.SparkSession

object t3 {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder().getOrCreate()

    spark.sql(
      """
        |from(from hhd.tra
        |   select
        |   distinct
        |       hour(actionId) time,
        |       count(car) carCount
        |   group by hour(actionId))
        |select
        |   time,
        |   carCount,
        |   concat(round((sum(carCount) over(order by time rows 6 preceding)/sum(carCount) over())*100,2),'%') rate,
        |   if(sum(carCount) over(order by time rows 6 preceding)/sum(carCount) over() >= 0.3,'繁忙','不繁忙') detail
        |""".stripMargin)
  }
}